package com.formula.datastructure.question.tree;

import com.formula.datastructure.standard.tree.binary.BinLinkedTree;
import com.formula.datastructure.standard.tree.normal.NormalLinkedNode;
import com.formula.datastructure.standard.tree.normal.NormalLinkedTree;
import com.formula.datastructure.util.DataUtil;

// The transform of normal tree and binary tree
public class Quest08 {
    public static void main(String[] args) {
        normalToBin();
    }

    public static void normalToBin() {
        NormalLinkedNode root = new NormalLinkedNode(0);

        NormalLinkedNode nodeA1 = new NormalLinkedNode(12);
        NormalLinkedNode nodeA2 = new NormalLinkedNode(16);
        NormalLinkedNode nodeB1 = new NormalLinkedNode(DataUtil.genNumber(100));
        NormalLinkedNode nodeB2 = new NormalLinkedNode(DataUtil.genNumber(100));
        NormalLinkedNode nodeB3 = new NormalLinkedNode(DataUtil.genNumber(100));
        NormalLinkedNode nodeC1 = new NormalLinkedNode(DataUtil.genNumber(100));
        NormalLinkedNode nodeC2 = new NormalLinkedNode(DataUtil.genNumber(100));
        NormalLinkedNode nodeC3 = new NormalLinkedNode(DataUtil.genNumber(100));
        NormalLinkedNode nodeC4 = new NormalLinkedNode(DataUtil.genNumber(100));
        NormalLinkedNode nodeD1 = new NormalLinkedNode(DataUtil.genNumber(100));
        NormalLinkedNode nodeD2 = new NormalLinkedNode(DataUtil.genNumber(100));
        NormalLinkedNode nodeD3 = new NormalLinkedNode(DataUtil.genNumber(100));
        NormalLinkedNode nodeD4 = new NormalLinkedNode(DataUtil.genNumber(100));

        root.addChild(nodeA1);
        root.addChild(nodeA2);
        nodeA1.addChild(nodeB1);
        nodeA1.addChild(nodeB2);
        nodeA2.addChild(nodeB3);
        nodeB2.addChild(nodeC2);
        nodeB1.addChild(nodeC1);
        nodeB3.addChild(nodeC3);
        nodeB3.addChild(nodeC4);

        nodeC1.addChild(nodeD1);
        nodeC2.addChild(nodeD2);
        nodeC3.addChild(nodeD3);
        nodeC3.addChild(nodeD4);

        NormalLinkedTree tree = new NormalLinkedTree(root);
        BinLinkedTree binTree = tree.transferToBin();
        System.out.println(binTree.getDepth());
    }
}
